/*
 * 
 *     This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 * 
 * BoogieMan - 2009
 *
 */

using System;
using System.Collections.Generic;
using System.Text;

namespace WoW.DataManager
{
    /// <summary>Object to access AreaTable.dbc</summary>
    public class AreaTable : DBCFile
    {
        public AreaTable() : base(@"DBFilesClient\AreaTable.dbc")
        {
        }

        /// <summary>Returns Area Name for a given AreaID (eg, Northshire Valley, Sentinel Hill, Moonbrook, etc)</summary>
        public String getAreaName(uint areaid)
        {
            for (uint i = 0; i < wdbc_header.nRecords; i++)
            {
                uint id = getFieldAsUint32(i, 0);

                if (id == areaid)
                    return getStringForField(i, 11);
            }

            throw new Exception("areaid wasn't found");
        }

        /// <summary>Returns MapID for a given AreaID (eg, Goldshire is on MapID=0, Astranaar is on MapID=1)</summary>
        public uint getMapId(uint areaid)
        {
            for (uint i = 0; i < wdbc_header.nRecords; i++)
            {
                uint id = getFieldAsUint32(i, 0);

                if (id == areaid)
                    return getFieldAsUint32(i, 1);
            }

            throw new Exception("areaid wasn't found");
        }

        /// <summary>Returns RegionID for a given AreaID (wtf is a RegionID though?)</summary>
        public uint getRegionID(uint areaid)
        {
            for (uint i = 0; i < wdbc_header.nRecords; i++)
            {
                uint id = getFieldAsUint32(i, 0);

                if (id == areaid)
                    return getFieldAsUint32(i, 2);
            }

            throw new Exception("areaid wasn't found");
        }
    }
}
